package models;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

import play.db.jpa.Model;

@Entity
@Inheritance
@DiscriminatorColumn(discriminatorType=DiscriminatorType.INTEGER, name="discriminator")
@DiscriminatorValue(value="0")
public abstract class Pessoa extends Model {
	private String email;

	@OneToMany(cascade=CascadeType.ALL, orphanRemoval=true)
	@JoinColumn(name = "pessoa_id")
	private Set<Endereco> enderecos = new HashSet<Endereco>();
	@OneToMany(cascade=CascadeType.ALL, orphanRemoval=true)
	@JoinColumn(name = "pessoa_id")
	private Set<Telefone> telefones = new HashSet<Telefone>();

	public Set<Endereco> getEnderecos() {
		return enderecos;
	}
	
	public void addEndereco(Endereco endereco) {
		if (endereco != null) {
			this.enderecos.add(endereco);
		}
	}

	public void addTelefone(Telefone telefone) {
		if (telefone != null) {
			this.telefones.add(telefone);
		}
	}
	
	public Set<Telefone> getTelefones() {
		return telefones;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}
}
